home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-34.z / elisp-34 (.txt)
GNU Info File  |  1998-05-26  |  48KB  |  839 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Daylight Savings,  Next: Diary Customizing,  Prev: Time Display Format,  Up: Calendar
  32. Daylight Savings Time
  33. =====================
  34.    Emacs understands the difference between standard time and daylight
  35. savings time--the times given for sunrise, sunset, solstices,
  36. equinoxes, and the phases of the moon take that into account.  The rules
  37. for daylight savings time vary from place to place and have also varied
  38. historically from year to year.  To do the job properly, Emacs needs to
  39. know which rules to use.
  40.    Some operating systems keep track of the rules that apply to the
  41. place where you are; on these systems, Emacs gets the information it
  42. needs from the system automatically.  If some or all of this
  43. information is missing, Emacs fills in the gaps with the rules
  44. currently used in Cambridge, Massachusetts, which is the center of
  45. GNU's world.
  46.    If the default choice of rules is not appropriate for your location,
  47. you can tell Emacs the rules to use by setting the variables
  48. `calendar-daylight-savings-starts' and
  49. `calendar-daylight-savings-ends'.  Their values should be Lisp
  50. expressions that refer to the variable `year', and evaluate to the
  51. Gregorian date on which daylight savings time starts or (respectively)
  52. ends, in the form of a list `(MONTH DAY YEAR)'.  The values should be
  53. `nil' if your area does not use daylight savings time.
  54.    Emacs uses these expressions to determine the start and end dates of
  55. daylight savings time as holidays and for correcting times of day in the
  56. solar and lunar calculations.
  57.    The values for Cambridge, Massachusetts are as follows:
  58.      (calendar-nth-named-day 1 0 4 year)
  59.      (calendar-nth-named-day -1 0 10 year)
  60. i.e., the first 0th day (Sunday) of the fourth month (April) in the
  61. year specified by `year', and the last Sunday of the tenth month
  62. (October) of that year.  If daylight savings time were changed to start
  63. on October 1, you would set `calendar-daylight-savings-starts' to this:
  64.      (list 10 1 year)
  65.    For a more complex example, suppose daylight savings time begins on
  66. the first of Nisan on the Hebrew calendar.  You should set
  67. `calendar-daylight-savings-starts' to this value:
  68.      (calendar-gregorian-from-absolute
  69.        (calendar-absolute-from-hebrew
  70.          (list 1 1 (+ year 3760))))
  71. because Nisan is the first month in the Hebrew calendar and the Hebrew
  72. year differs from the Gregorian year by 3760 at Nisan.
  73.    If there is no daylight savings time at your location, or if you want
  74. all times in standard time, set `calendar-daylight-savings-starts' and
  75. `calendar-daylight-savings-ends' to `nil'.
  76.    The variable `calendar-daylight-time-offset' specifies the
  77. difference between daylight savings time and standard time, measured in
  78. minutes.  The value for Cambridge is 60.
  79.    The variable `calendar-daylight-savings-starts-time' and the
  80. variable `calendar-daylight-savings-ends-time' specify the number of
  81. minutes after midnight local time when the transition to and from
  82. daylight savings time should occur.  For Cambridge, both variables'
  83. values are 120.
  84. File: elisp,  Node: Diary Customizing,  Next: Hebrew/Islamic Entries,  Prev: Daylight Savings,  Up: Calendar
  85. Customizing the Diary
  86. =====================
  87.    Ordinarily, the mode line of the diary buffer window indicates any
  88. holidays that fall on the date of the diary entries.  The process of
  89. checking for holidays can take several seconds, so including holiday
  90. information delays the display of the diary buffer noticeably.  If you'd
  91. prefer to have a faster display of the diary buffer but without the
  92. holiday information, set the variable `holidays-in-diary-buffer' to
  93. `nil'.
  94.    The variable `number-of-diary-entries' controls the number of days
  95. of diary entries to be displayed at one time.  It affects the initial
  96. display when `view-diary-entries-initially' is `t', as well as the
  97. command `M-x diary'.  For example, the default value is 1, which says
  98. to display only the current day's diary entries.  If the value is 2,
  99. both the current day's and the next day's entries are displayed.  The
  100. value can also be a vector of seven elements: for example, if the value
  101. is `[0 2 2 2 2 4 1]' then no diary entries appear on Sunday, the
  102. current date's and the next day's diary entries appear Monday through
  103. Thursday, Friday through Monday's entries appear on Friday, while on
  104. Saturday only that day's entries appear.
  105.    The variable `print-diary-entries-hook' is a normal hook run after
  106. preparation of a temporary buffer containing just the diary entries
  107. currently visible in the diary buffer.  (The other, irrelevant diary
  108. entries are really absent from the temporary buffer; in the diary
  109. buffer, they are merely hidden.)  The default value of this hook does
  110. the printing with the command `lpr-buffer'.  If you want to use a
  111. different command to do the printing, just change the value of this
  112. hook.  Other uses might include, for example, rearranging the lines into
  113. order by day and time.
  114.    You can customize the form of dates in your diary file, if neither
  115. the standard American nor European styles suits your needs, by setting
  116. the variable `diary-date-forms'.  This variable is a list of patterns
  117. for recognizing a date.  Each date pattern is a list whose elements may
  118. be regular expressions (*note Regular Expressions::.) or the symbols
  119. `month', `day', `year', `monthname', and `dayname'.  All these elements
  120. serve as patterns that match certain kinds of text in the diary file.
  121. In order for the date pattern, as a whole, to match, all of its
  122. elements must match consecutively.
  123.    A regular expression in a date pattern matches in its usual fashion,
  124. using the standard syntax table altered so that `*' is a word
  125. constituent.
  126.    The symbols `month', `day', `year', `monthname', and `dayname' match
  127. the month number, day number, year number, month name, and day name of
  128. the date being considered.  The symbols that match numbers allow
  129. leading zeros; those that match names allow three-letter abbreviations
  130. and capitalization.  All the symbols can match `*'; since `*' in a
  131. diary entry means "any day", "any month", and so on, it should match
  132. regardless of the date being considered.
  133.    The default value of `diary-date-forms' in the American style is
  134. this:
  135.      ((month "/" day "[^/0-9]")
  136.       (month "/" day "/" year "[^0-9]")
  137.       (monthname " *" day "[^,0-9]")
  138.       (monthname " *" day ", *" year "[^0-9]")
  139.       (dayname "\\W"))
  140.    The date patterns in the list must be *mutually exclusive* and must
  141. not match any portion of the diary entry itself, just the date and one
  142. character of whitespace.  If, to be mutually exclusive, the pattern
  143. must match a portion of the diary entry text--beyond the whitespace
  144. that ends the date--then the first element of the date pattern *must*
  145. be `backup'.  This causes the date recognizer to back up to the
  146. beginning of the current word of the diary entry, after finishing the
  147. match.  Even if you use `backup', the date pattern must absolutely not
  148. match more than a portion of the first word of the diary entry.  The
  149. default value of `diary-date-forms' in the European style is this list:
  150.      ((day "/" month "[^/0-9]")
  151.       (day "/" month "/" year "[^0-9]")
  152.       (backup day " *" monthname "\\W+\\<[^*0-9]")
  153.       (day " *" monthname " *" year "[^0-9]")
  154.       (dayname "\\W"))
  155. Notice the use of `backup' in the third pattern, because it needs to
  156. match part of a word beyond the date itself to distinguish it from the
  157. fourth pattern.
  158. File: elisp,  Node: Hebrew/Islamic Entries,  Next: Fancy Diary Display,  Prev: Diary Customizing,  Up: Calendar
  159. Hebrew- and Islamic-Date Diary Entries
  160. ======================================
  161.    Your diary file can have entries based on Hebrew or Islamic dates, as
  162. well as entries based on the world-standard Gregorian calendar.
  163. However, because recognition of such entries is time-consuming and most
  164. people don't use them, you must explicitly enable their use.  If you
  165. want the diary to recognize Hebrew-date diary entries, for example, you
  166. must do this:
  167.      (add-hook 'nongregorian-diary-listing-hook 'list-hebrew-diary-entries)
  168.      (add-hook 'nongregorian-diary-marking-hook 'mark-hebrew-diary-entries)
  169. If you want Islamic-date entries, do this:
  170.      (add-hook 'nongregorian-diary-listing-hook 'list-islamic-diary-entries)
  171.      (add-hook 'nongregorian-diary-marking-hook 'mark-islamic-diary-entries)
  172.    Hebrew- and Islamic-date diary entries have the same formats as
  173. Gregorian-date diary entries, except that `H' precedes a Hebrew date
  174. and `I' precedes an Islamic date.  Moreover, because the Hebrew and
  175. Islamic month names are not uniquely specified by the first three
  176. letters, you may not abbreviate them.  For example, a diary entry for
  177. the Hebrew date Heshvan 25 could look like this:
  178.      HHeshvan 25 Happy Hebrew birthday!
  179. and would appear in the diary for any date that corresponds to Heshvan
  180. 25 on the Hebrew calendar.  And here is  Islamic-date diary entry  that
  181. matches Dhu al-Qada 25:
  182.      IDhu al-Qada 25 Happy Islamic birthday!
  183.    As with Gregorian-date diary entries, Hebrew- and Islamic-date
  184. entries are nonmarking if they are preceded with an ampersand (`&').
  185.    Here is a table of commands used in the calendar to create diary
  186. entries that match the selected date and other dates that are similar
  187. in the Hebrew or Islamic calendar:
  188. `i h d'
  189.      Add a diary entry for the Hebrew date corresponding to the
  190.      selected date (`insert-hebrew-diary-entry').
  191. `i h m'
  192.      Add a diary entry for the day of the Hebrew month corresponding to
  193.      the selected date (`insert-monthly-hebrew-diary-entry').  This
  194.      diary entry matches any date that has the same Hebrew
  195.      day-within-month as the selected date.
  196. `i h y'
  197.      Add a diary entry for the day of the Hebrew year corresponding to
  198.      the selected date (`insert-yearly-hebrew-diary-entry').  This diary
  199.      entry matches any date which has the same Hebrew month and
  200.      day-within-month as the selected date.
  201. `i i d'
  202.      Add a diary entry for the Islamic date corresponding to the
  203.      selected date (`insert-islamic-diary-entry').
  204. `i i m'
  205.      Add a diary entry for the day of the Islamic month corresponding
  206.      to the selected date (`insert-monthly-islamic-diary-entry').
  207. `i i y'
  208.      Add a diary entry for the day of the Islamic year corresponding to
  209.      the selected date (`insert-yearly-islamic-diary-entry').
  210.    These commands work much like the corresponding commands for ordinary
  211. diary entries: they apply to the date that point is on in the calendar
  212. window, and what they do is insert just the date portion of a diary
  213. entry at the end of your diary file.  You must then insert the rest of
  214. the diary entry.
  215. File: elisp,  Node: Fancy Diary Display,  Next: Sexp Diary Entries,  Prev: Hebrew/Islamic Entries,  Up: Calendar
  216. Fancy Diary Display
  217. ===================
  218.    Diary display works by preparing the diary buffer and then running
  219. the hook `diary-display-hook'.  The default value of this hook
  220. (`simple-diary-display') hides the irrelevant diary entries and then
  221. displays the buffer.  However, if you specify the hook as follows,
  222.      (add-hook 'diary-display-hook 'fancy-diary-display)
  223. this enables fancy diary display.  It displays diary entries and
  224. holidays by copying them into a special buffer that exists only for the
  225. sake of display.  Copying to a separate buffer provides an opportunity
  226. to change the displayed text to make it prettier--for example, to sort
  227. the entries by the dates they apply to.
  228.    As with simple diary display, you can print a hard copy of the buffer
  229. with `print-diary-entries'.  To print a hard copy of a day-by-day diary
  230. for a week by positioning point on Sunday of that week, type `7 d' and
  231. then do `M-x print-diary-entries'.  As usual, the inclusion of the
  232. holidays slows down the display slightly; you can speed things up by
  233. setting the variable `holidays-in-diary-buffer' to `nil'.
  234.    Ordinarily, the fancy diary buffer does not show days for which
  235. there are no diary entries, even if that day is a holiday.  If you want
  236. such days to be shown in the fancy diary buffer, set the variable
  237. `diary-list-include-blanks' to `t'.
  238.    If you use the fancy diary display, you can use the normal hook
  239. `list-diary-entries-hook' to sort each day's diary entries by their
  240. time of day.  Here's how
  241.      (add-hook 'list-diary-entries-hook 'sort-diary-entries t)
  242. For each day, this sorts diary entries that begin with a recognizable
  243. time of day according to their times.  Diary entries without times come
  244. first within each day.
  245.    Fancy diary display also has the ability to process included diary
  246. files.  This permits a group of people to share a diary file for events
  247. that apply to all of them.  Lines in the diary file of this form:
  248.      #include "FILENAME"
  249. includes the diary entries from the file FILENAME in the fancy diary
  250. buffer.  The include mechanism is recursive, so that included files can
  251. include other files, and so on; you must be careful not to have a cycle
  252. of inclusions, of course.  Here is how to enable the include facility:
  253.      (add-hook 'list-diary-entries-hook 'include-other-diary-files)
  254.      (add-hook 'mark-diary-entries-hook 'mark-included-diary-files)
  255.    The include mechanism works only with the fancy diary display,
  256. because ordinary diary display shows the entries directly from your
  257. diary file.
  258. File: elisp,  Node: Sexp Diary Entries,  Next: Appt Customizing,  Prev: Fancy Diary Display,  Up: Calendar
  259. Sexp Entries and the Fancy Diary Display
  260. ========================================
  261.    Sexp diary entries allow you to do more than just have complicated
  262. conditions under which a diary entry applies.  If you use the fancy
  263. diary display, sexp entries can generate the text of the entry depending
  264. on the date itself.  For example, an anniversary diary entry can insert
  265. the number of years since the anniversary date into the text of the
  266. diary entry.  Thus the `%d' in this dairy entry:
  267.      %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
  268. gets replaced by the age, so on October 31, 1990 the entry appears in
  269. the fancy diary buffer like this:
  270.      Arthur's birthday (42 years old)
  271. If the diary file instead contains this entry:
  272.      %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
  273. the entry in the fancy diary buffer for October 31, 1990 appears like
  274. this:
  275.      Arthur's 42nd birthday
  276.    Similarly, cyclic diary entries can interpolate the number of
  277. repetitions that have occurred:
  278.      %%(diary-cyclic 50 1 1 1990) Renew medication (%d%s time)
  279. looks like this:
  280.      Renew medication (5th time)
  281. in the fancy diary display on September 8, 1990.
  282.    The generality of sexp diary entries lets you specify any diary entry
  283. that you can describe algorithmically.  A sexp diary entry contains an
  284. expression that computes whether the entry applies to any given date.
  285. If its value is non-`nil', the entry applies to that date; otherwise,
  286. it does not.  The expression can use the variable  `date' to find the
  287. date being considered; its value is a list (MONTH DAY YEAR) that refers
  288. to the Gregorian calendar.
  289.    Suppose you get paid on the 21st of the month if it is a weekday, and
  290. on the Friday before if the 21st is on a weekend.  Here is how to write
  291. a sexp diary entry that matches those dates:
  292.      &%%(let ((dayname (calendar-day-of-week date))
  293.               (day (car (cdr date))))
  294.            (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
  295.                (and (memq day '(19 20)) (= dayname 5)))
  296.               ) Pay check deposited
  297.    The following sexp diary entries take advantage of the ability (in
  298. the fancy diary display) to concoct diary entries whose text varies
  299. based on the date:
  300. `%%(diary-sunrise-sunset)'
  301.      Make a diary entry for the local times of today's sunrise and
  302.      sunset.
  303. `%%(diary-phases-of-moon)'
  304.      Make a diary entry for the phases (quarters) of the moon.
  305. `%%(diary-day-of-year)'
  306.      Make a diary entry with today's day number in the current year and
  307.      the number of days remaining in the current year.
  308. `%%(diary-iso-date)'
  309.      Make a diary entry with today's equivalent ISO commercial date.
  310. `%%(diary-julian-date)'
  311.      Make a diary entry with today's equivalent date on the Julian
  312.      calendar.
  313. `%%(diary-astro-day-number)'
  314.      Make a diary entry with today's equivalent astronomical (Julian)
  315.      day number.
  316. `%%(diary-hebrew-date)'
  317.      Make a diary entry with today's equivalent date on the Hebrew
  318.      calendar.
  319. `%%(diary-islamic-date)'
  320.      Make a diary entry with today's equivalent date on the Islamic
  321.      calendar.
  322. `%%(diary-french-date)'
  323.      Make a diary entry with today's equivalent date on the French
  324.      Revolutionary calendar.
  325. `%%(diary-mayan-date)'
  326.      Make a diary entry with today's equivalent date on the Mayan
  327.      calendar.
  328. Thus including the diary entry
  329.      &%%(diary-hebrew-date)
  330. causes every day's diary display to contain the equivalent date on the
  331. Hebrew calendar, if you are using the fancy diary display.  (With simple
  332. diary display, the line `&%%(diary-hebrew-date)' appears in the diary
  333. for any date, but does nothing particularly useful.)
  334.    These functions can be used to construct sexp diary entries based on
  335. the Hebrew calendar in certain standard ways:
  336. `%%(diary-rosh-hodesh)'
  337.      Make a diary entry that tells the occurrence and ritual
  338.      announcement of each new Hebrew month.
  339. `%%(diary-parasha)'
  340.      Make a Saturday diary entry that tells the weekly synagogue
  341.      scripture reading.
  342. `%%(diary-sabbath-candles)'
  343.      Make a Friday diary entry that tells the *local time* of Sabbath
  344.      candle lighting.
  345. `%%(diary-omer)'
  346.      Make a diary entry that gives the omer count, when appropriate.
  347. `%%(diary-yahrzeit MONTH DAY YEAR) NAME'
  348.      Make a diary entry marking the anniversary of a date of death.
  349.      The date is the *Gregorian* (civil) date of death.  The diary
  350.      entry appears on the proper Hebrew calendar anniversary and on the
  351.      day before.  (In the European style, the order of the parameters
  352.      is changed to DAY, MONTH, YEAR.)
  353. File: elisp,  Node: Appt Customizing,  Prev: Sexp Diary Entries,  Up: Calendar
  354. Customizing Appointment Reminders
  355. =================================
  356.    You can specify exactly how Emacs reminds you of an appointment, and
  357. how far in advance it begins doing so, by setting these variables:
  358. `appt-message-warning-time'
  359.      The time in minutes before an appointment that the reminder
  360.      begins.  The default is 10 minutes.
  361. `appt-audible'
  362.      If this is non-`nil', Emacs rings the terminal bell for
  363.      appointment reminders.  The default is `t'.
  364. `appt-visible'
  365.      If this is non-`nil', Emacs displays the appointment message in
  366.      the echo area.  The default is `t'.
  367. `appt-display-mode-line'
  368.      If this is non-`nil', Emacs displays the number of minutes to the
  369.      appointment on the mode line.  The default is `t'.
  370. `appt-msg-window'
  371.      If this is non-`nil', Emacs displays the appointment message in
  372.      another window.  The default is `t'.
  373. `appt-disp-window-function'
  374.      This variable holds a function to use to create the other window
  375.      for the appointment message.
  376. `appt-delete-window-function'
  377.      This variable holds a function to use to get rid of the appointment
  378.      message window, when its time is up.
  379. `appt-display-duration'
  380.      The number of seconds to display an appointment message.  The
  381.      default is 5 seconds.
  382. File: elisp,  Node: Tips,  Next: GNU Emacs Internals,  Prev: Calendar,  Up: Top
  383. Tips and Standards
  384. ******************
  385.    This chapter describes no additional features of Emacs Lisp.
  386. Instead it gives advice on making effective use of the features
  387. described in the previous chapters.
  388. * Menu:
  389. * Style Tips::                Writing clean and robust programs.
  390. * Compilation Tips::          Making compiled code run fast.
  391. * Documentation Tips::        Writing readable documentation strings.
  392. * Comment Tips::          Conventions for writing comments.
  393. * Library Headers::           Standard headers for library packages.
  394. File: elisp,  Node: Style Tips,  Next: Compilation Tips,  Up: Tips
  395. Writing Clean Lisp Programs
  396. ===========================
  397.    Here are some tips for avoiding common errors in writing Lisp code
  398. intended for widespread use:
  399.    * Since all global variables share the same name space, and all
  400.      functions share another name space, you should choose a short word
  401.      to distinguish your program from other Lisp programs.  Then take
  402.      care to begin the names of all global variables, constants, and
  403.      functions with the chosen prefix.  This helps avoid name conflicts.
  404.      This recommendation applies even to names for traditional Lisp
  405.      primitives that are not primitives in Emacs Lisp--even to `cadr'.
  406.      Believe it or not, there is more than one plausible way to define
  407.      `cadr'.  Play it safe; append your name prefix to produce a name
  408.      like `foo-cadr' or `mylib-cadr' instead.
  409.      If you write a function that you think ought to be added to Emacs
  410.      under a certain name, such as `twiddle-files', don't call it by
  411.      that name in your program.  Call it `mylib-twiddle-files' in your
  412.      program, and send mail to `bug-gnu-emacs@prep.ai.mit.edu'
  413.      suggesting we add it to Emacs.  If and when we do, we can change
  414.      the name easily enough.
  415.      If one prefix is insufficient, your package may use two or three
  416.      alternative common prefixes, so long as they make sense.
  417.      Separate the prefix from the rest of the symbol name with a hyphen,
  418.      `-'.  This will be consistent with Emacs itself and with most Emacs
  419.      Lisp programs.
  420.    * It is often useful to put a call to `provide' in each separate
  421.      library program, at least if there is more than one entry point to
  422.      the program.
  423.    * If a file requires certain other library programs to be loaded
  424.      beforehand, then the comments at the beginning of the file should
  425.      say so.  Also, use `require' to make sure they are loaded.
  426.    * If one file FOO uses a macro defined in another file BAR, FOO
  427.      should contain this expression before the first use of the macro:
  428.           (eval-when-compile (require 'BAR))
  429.      (And BAR should contain `(provide 'BAR)', to make the `require'
  430.      work.)  This will cause BAR to be loaded when you byte-compile
  431.      FOO.  Otherwise, you risk compiling FOO without the necessary
  432.      macro loaded, and that would produce compiled code that won't work
  433.      right.  *Note Compiling Macros::.
  434.      Using `eval-when-compile' avoids loading BAR when the compiled
  435.      version of FOO is *used*.
  436.    * If you define a major mode, make sure to run a hook variable using
  437.      `run-hooks', just as the existing major modes do.  *Note Hooks::.
  438.    * If the purpose of a function is to tell you whether a certain
  439.      condition is true or false, give the function a name that ends in
  440.      `p'.  If the name is one word, add just `p'; if the name is
  441.      multiple words, add `-p'.  Examples are `framep' and
  442.      `frame-live-p'.
  443.    * If a user option variable records a true-or-false condition, give
  444.      it a name that ends in `-flag'.
  445.    * Please do not define `C-c LETTER' as a key in your major modes.
  446.      These sequences are reserved for users; they are the *only*
  447.      sequences reserved for users, so we cannot do without them.
  448.      Instead, define sequences consisting of `C-c' followed by a control
  449.      character, a digit, or certain punctuation characters.  These
  450.      sequences are reserved for major modes.
  451.      Changing all the major modes in Emacs 18 so they would follow this
  452.      convention was a lot of work.  Abandoning this convention would
  453.      make that work go to waste, and inconvenience users.
  454.    * Sequences consisting of `C-c' followed by `{', `}', `<', `>', `:'
  455.      or `;' are also reserved for major modes.
  456.    * Sequences consisting of `C-c' followed by any other punctuation
  457.      character are allocated for minor modes.  Using them in a major
  458.      mode is not absolutely prohibited, but if you do that, the major
  459.      mode binding may be shadowed from time to time by minor modes.
  460.    * You should not bind `C-h' following any prefix character (including
  461.      `C-c').  If you don't bind `C-h', it is automatically available as
  462.      a help character for listing the subcommands of the prefix
  463.      character.
  464.    * You should not bind a key sequence ending in ESC except following
  465.      another ESC.  (That is, it is ok to bind a sequence ending in `ESC
  466.      ESC'.)
  467.      The reason for this rule is that a non-prefix binding for ESC in
  468.      any context prevents recognition of escape sequences as function
  469.      keys in that context.
  470.    * Applications should not bind mouse events based on button 1 with
  471.      the shift key held down.  These events include `S-mouse-1',
  472.      `M-S-mouse-1', `C-S-mouse-1', and so on.  They are reserved for
  473.      users.
  474.    * Modes should redefine `mouse-2' as a command to follow some sort of
  475.      reference in the text of a buffer, if users usually would not want
  476.      to alter the text in that buffer by hand.  Modes such as Dired,
  477.      Info, Compilation, and Occur redefine it in this way.
  478.    * When a package provides a modification of ordinary Emacs behavior,
  479.      it is good to include a command to enable and disable the feature,
  480.      Provide a command named `WHATEVER-mode' which turns the feature on
  481.      or off, and make it autoload (*note Autoload::.).  Design the
  482.      package so that simply loading it has no visible effect--that
  483.      should not enable the feature.  Users will request the feature by
  484.      invoking the command.
  485.    * It is a bad idea to define aliases for the Emacs primitives.  Use
  486.      the standard names instead.
  487.    * Redefining an Emacs primitive is an even worse idea.  It may do
  488.      the right thing for a particular program, but there is no telling
  489.      what other programs might break as a result.
  490.    * If a file does replace any of the functions or library programs of
  491.      standard Emacs, prominent comments at the beginning of the file
  492.      should say which functions are replaced, and how the behavior of
  493.      the replacements differs from that of the originals.
  494.    * Please keep the names of your Emacs Lisp source files to 13
  495.      characters or less.  This way, if the files are compiled, the
  496.      compiled files' names will be 14 characters or less, which is
  497.      short enough to fit on all kinds of Unix systems.
  498.    * Don't use `next-line' or `previous-line' in programs; nearly
  499.      always, `forward-line' is more convenient as well as more
  500.      predictable and robust.  *Note Text Lines::.
  501.    * Don't call functions that set the mark, unless setting the mark is
  502.      one of the intended features of your program.  The mark is a
  503.      user-level feature, so it is incorrect to change the mark except
  504.      to supply a value for the user's benefit.  *Note The Mark::.
  505.      In particular, don't use these functions:
  506.         * `beginning-of-buffer', `end-of-buffer'
  507.         * `replace-string', `replace-regexp'
  508.      If you just want to move point, or replace a certain string,
  509.      without any of the other features intended for interactive users,
  510.      you can replace these functions with one or two lines of simple
  511.      Lisp code.
  512.    * Use lists rather than vectors, except when there is a particular
  513.      reason to use a vector.  Lisp has more facilities for manipulating
  514.      lists than for vectors, and working with lists is usually more
  515.      convenient.
  516.      Vectors are advantageous for tables that are substantial in size
  517.      and are accessed in random order (not searched front to back),
  518.      provided there is no need to insert or delete elements (only lists
  519.      allow that).
  520.    * The recommended way to print a message in the echo area is with
  521.      the `message' function, not `princ'.  *Note The Echo Area::.
  522.    * When you encounter an error condition, call the function `error'
  523.      (or `signal').  The function `error' does not return.  *Note
  524.      Signaling Errors::.
  525.      Do not use `message', `throw', `sleep-for', or `beep' to report
  526.      errors.
  527.    * An error message should start with a capital letter but should not
  528.      end with a period.
  529.    * Many commands that take a long time to execute display a message
  530.      that says `Operating...' when they start, and change it to
  531.      `Operating...done' when they finish.  Please keep the style of
  532.      these messages uniform: *no* space around the ellipsis, and *no*
  533.      period at the end.
  534.    * Try to avoid using recursive edits.  Instead, do what the Rmail `e'
  535.      command does: use a new local keymap that contains one command
  536.      defined to switch back to the old local keymap.  Or do what the
  537.      `edit-options' command does: switch to another buffer and let the
  538.      user switch back at will.  *Note Recursive Editing::.
  539.    * In some other systems there is a convention of choosing variable
  540.      names that begin and end with `*'.  We don't use that convention
  541.      in Emacs Lisp, so please don't use it in your programs.  (Emacs
  542.      uses such names only for program-generated buffers.)  The users
  543.      will find Emacs more coherent if all libraries use the same
  544.      conventions.
  545.    * Try to avoid compiler warnings about undefined free variables, by
  546.      adding `defvar' definitions for these variables.
  547.      If you bind a variable in one function, and use it or set it in
  548.      another function, the compiler warns about the latter function
  549.      unless the variable has a definition.  But often these variables
  550.      have short names, and it is not clean for Lisp packages to define
  551.      such variables names.  Therefore, you should rename the variable
  552.      to start with the name prefix used for the other functions and
  553.      variables in your package.
  554.    * Indent each function with `C-M-q' (`indent-sexp') using the
  555.      default indentation parameters.
  556.    * Don't make a habit of putting close-parentheses on lines by
  557.      themselves; Lisp programmers find this disconcerting.  Once in a
  558.      while, when there is a sequence of many consecutive
  559.      close-parentheses, it may make sense to split them in one or two
  560.      significant places.
  561.    * Please put a copyright notice on the file if you give copies to
  562.      anyone.  Use the same lines that appear at the top of the Lisp
  563.      files in Emacs itself.  If you have not signed papers to assign
  564.      the copyright to the Foundation, then place your name in the
  565.      copyright notice in place of the Foundation's name.
  566. File: elisp,  Node: Compilation Tips,  Next: Documentation Tips,  Prev: Style Tips,  Up: Tips
  567. Tips for Making Compiled Code Fast
  568. ==================================
  569.    Here are ways of improving the execution speed of byte-compiled Lisp
  570. programs.
  571.    * Use the `profile' library to profile your program.  See the file
  572.      `profile.el' for instructions.
  573.    * Use iteration rather than recursion whenever possible.  Function
  574.      calls are slow in Emacs Lisp even when a compiled function is
  575.      calling another compiled function.
  576.    * Using the primitive list-searching functions `memq', `member',
  577.      `assq', or `assoc' is even faster than explicit iteration.  It may
  578.      be worth rearranging a data structure so that one of these
  579.      primitive search functions can be used.
  580.    * Certain built-in functions are handled specially in byte-compiled
  581.      code, avoiding the need for an ordinary function call.  It is a
  582.      good idea to use these functions rather than alternatives.  To see
  583.      whether a function is handled specially by the compiler, examine
  584.      its `byte-compile' property.  If the property is non-`nil', then
  585.      the function is handled specially.
  586.      For example, the following input will show you that `aref' is
  587.      compiled specially (*note Array Functions::.) while `elt' is not
  588.      (*note Sequence Functions::.):
  589.           (get 'aref 'byte-compile)
  590.                => byte-compile-two-args
  591.           
  592.           (get 'elt 'byte-compile)
  593.                => nil
  594.    * If calling a small function accounts for a  substantial part of
  595.      your program's running time, make the function inline.  This
  596.      eliminates the function call overhead.  Since making a function
  597.      inline reduces the flexibility of changing the program, don't do
  598.      it unless it gives a noticeable speedup in something slow enough
  599.      that users care about the speed.  *Note Inline Functions::.
  600. File: elisp,  Node: Documentation Tips,  Next: Comment Tips,  Prev: Compilation Tips,  Up: Tips
  601. Tips for Documentation Strings
  602. ==============================
  603.    Here are some tips for the writing of documentation strings.
  604.    * Every command, function, or variable intended for users to know
  605.      about should have a documentation string.
  606.    * An internal variable or subroutine of a Lisp program might as well
  607.      have a documentation string.  In earlier Emacs versions, you could
  608.      save space by using a comment instead of a documentation string,
  609.      but that is no longer the case.
  610.    * The first line of the documentation string should consist of one
  611.      or two complete sentences that stand on their own as a summary.
  612.      `M-x apropos' displays just the first line, and if it doesn't
  613.      stand on its own, the result looks bad.  In particular, start the
  614.      first line with a capital letter and end with a period.
  615.      The documentation string can have additional lines that expand on
  616.      the details of how to use the function or variable.  The
  617.      additional lines should be made up of complete sentences also, but
  618.      they may be filled if that looks good.
  619.    * For consistency, phrase the verb in the first sentence of a
  620.      documentation string as an infinitive with "to" omitted.  For
  621.      instance, use "Return the cons of A and B." in preference to
  622.      "Returns the cons of A and B."  Usually it looks good to do
  623.      likewise for the rest of the first paragraph.  Subsequent
  624.      paragraphs usually look better if they have proper subjects.
  625.    * Write documentation strings in the active voice, not the passive,
  626.      and in the present tense, not the future.  For instance, use
  627.      "Return a list containing A and B." instead of "A list containing
  628.      A and B will be returned."
  629.    * Avoid using the word "cause" (or its equivalents) unnecessarily.
  630.      Instead of, "Cause Emacs to display text in boldface," write just
  631.      "Display text in boldface."
  632.    * Do not start or end a documentation string with whitespace.
  633.    * Format the documentation string so that it fits in an Emacs window
  634.      on an 80-column screen.  It is a good idea for most lines to be no
  635.      wider than 60 characters.  The first line can be wider if
  636.      necessary to fit the information that ought to be there.
  637.      However, rather than simply filling the entire documentation
  638.      string, you can make it much more readable by choosing line breaks
  639.      with care.  Use blank lines between topics if the documentation
  640.      string is long.
  641.    * *Do not* indent subsequent lines of a documentation string so that
  642.      the text is lined up in the source code with the text of the first
  643.      line.  This looks nice in the source code, but looks bizarre when
  644.      users view the documentation.  Remember that the indentation
  645.      before the starting double-quote is not part of the string!
  646.    * When the user tries to use a disabled command, Emacs displays just
  647.      the first paragraph of its documentation string--everything
  648.      through the first blank line.  If you wish, you can choose which
  649.      information to include before the first blank line so as to make
  650.      this display useful.
  651.    * A variable's documentation string should start with `*' if the
  652.      variable is one that users would often want to set interactively.
  653.      If the value is a long list, or a function, or if the variable
  654.      would be set only in init files, then don't start the
  655.      documentation string with `*'.  *Note Defining Variables::.
  656.    * The documentation string for a variable that is a yes-or-no flag
  657.      should start with words such as "Non-nil means...", to make it
  658.      clear that all non-`nil' values are equivalent and indicate
  659.      explicitly what `nil' and non-`nil' mean.
  660.    * When a function's documentation string mentions the value of an
  661.      argument of the function, use the argument name in capital letters
  662.      as if it were a name for that value.  Thus, the documentation
  663.      string of the function `/' refers to its second argument as
  664.      `DIVISOR', because the actual argument name is `divisor'.
  665.      Also use all caps for meta-syntactic variables, such as when you
  666.      show the decomposition of a list or vector into subunits, some of
  667.      which may vary.
  668.    * When a documentation string refers to a Lisp symbol, write it as it
  669.      would be printed (which usually means in lower case), with
  670.      single-quotes around it.  For example: `lambda'.  There are two
  671.      exceptions: write t and nil without single-quotes.  (In this
  672.      manual, we normally do use single-quotes for those symbols.)
  673.    * Don't write key sequences directly in documentation strings.
  674.      Instead, use the `\\[...]' construct to stand for them.  For
  675.      example, instead of writing `C-f', write the construct
  676.      `\\[forward-char]'.  When Emacs displays the documentation string,
  677.      it substitutes whatever key is currently bound to `forward-char'.
  678.      (This is normally `C-f', but it may be some other character if the
  679.      user has moved key bindings.)  *Note Keys in Documentation::.
  680.    * In documentation strings for a major mode, you will want to refer
  681.      to the key bindings of that mode's local map, rather than global
  682.      ones.  Therefore, use the construct `\\<...>' once in the
  683.      documentation string to specify which key map to use.  Do this
  684.      before the first use of `\\[...]'.  The text inside the `\\<...>'
  685.      should be the name of the variable containing the local keymap for
  686.      the major mode.
  687.      It is not practical to use `\\[...]' very many times, because
  688.      display of the documentation string will become slow.  So use this
  689.      to describe the most important commands in your major mode, and
  690.      then use `\\{...}' to display the rest of the mode's keymap.
  691. File: elisp,  Node: Comment Tips,  Next: Library Headers,  Prev: Documentation Tips,  Up: Tips
  692. Tips on Writing Comments
  693. ========================
  694.    We recommend these conventions for where to put comments and how to
  695. indent them:
  696.      Comments that start with a single semicolon, `;', should all be
  697.      aligned to the same column on the right of the source code.  Such
  698.      comments usually explain how the code on the same line does its
  699.      job.  In Lisp mode and related modes, the `M-;'
  700.      (`indent-for-comment') command automatically inserts such a `;' in
  701.      the right place, or aligns such a comment if it is already present.
  702.      This and following examples are taken from the Emacs sources.
  703.           (setq base-version-list                 ; there was a base
  704.                 (assoc (substring fn 0 start-vn)  ; version to which
  705.                        file-version-assoc-list))  ; this looks like
  706.                                                   ; a subversion
  707.      Comments that start with two semicolons, `;;', should be aligned to
  708.      the same level of indentation as the code.  Such comments usually
  709.      describe the purpose of the following lines or the state of the
  710.      program at that point.  For example:
  711.           (prog1 (setq auto-fill-function
  712.                        ...
  713.                        ...
  714.             ;; update mode line
  715.             (force-mode-line-update)))
  716.      Every function that has no documentation string (because it is use
  717.      only internally within the package it belongs to), should have
  718.      instead a two-semicolon comment right before the function,
  719.      explaining what the function does and how to call it properly.
  720.      Explain precisely what each argument means and how the function
  721.      interprets its possible values.
  722. `;;;'
  723.      Comments that start with three semicolons, `;;;', should start at
  724.      the left margin.  Such comments are used outside function
  725.      definitions to make general statements explaining the design
  726.      principles of the program.  For example:
  727.           ;;; This Lisp code is run in Emacs
  728.           ;;; when it is to operate as a server
  729.           ;;; for other processes.
  730.      Another use for triple-semicolon comments is for commenting out
  731.      lines within a function.  We use triple-semicolons for this
  732.      precisely so that they remain at the left margin.
  733.           (defun foo (a)
  734.           ;;; This is no longer necessary.
  735.           ;;;  (force-mode-line-update)
  736.             (message "Finished with %s" a))
  737. `;;;;'
  738.      Comments that start with four semicolons, `;;;;', should be aligned
  739.      to the left margin and are used for headings of major sections of a
  740.      program.  For example:
  741.           ;;;; The kill ring
  742. The indentation commands of the Lisp modes in Emacs, such as `M-;'
  743. (`indent-for-comment') and TAB (`lisp-indent-line') automatically
  744. indent comments according to these conventions, depending on the number
  745. of semicolons.  *Note Manipulating Comments: (emacs)Comments.
  746. File: elisp,  Node: Library Headers,  Prev: Comment Tips,  Up: Tips
  747. Conventional Headers for Emacs Libraries
  748. ========================================
  749.    Emacs 19 has conventions for using special comments in Lisp libraries
  750. to divide them into sections and give information such as who wrote
  751. them.  This section explains these conventions.  First, an example:
  752.      ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers
  753.      
  754.      ;; Copyright (C) 1992 Free Software Foundation, Inc.
  755.      
  756.      ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
  757.      ;; Maintainer: Eric S. Raymond <esr@snark.thyrsus.com>
  758.      ;; Created: 14 Jul 1992
  759.      ;; Version: 1.2
  760.      ;; Keywords: docs
  761.      
  762.      ;; This file is part of GNU Emacs.
  763.      COPYING PERMISSIONS...
  764.    The very first line should have this format:
  765.      ;;; FILENAME --- DESCRIPTION
  766. The description should be complete in one line.
  767.    After the copyright notice come several "header comment" lines, each
  768. beginning with `;; HEADER-NAME:'.  Here is a table of the conventional
  769. possibilities for HEADER-NAME:
  770. `Author'
  771.      This line states the name and net address of at least the principal
  772.      author of the library.
  773.      If there are multiple authors, you can list them on continuation
  774.      lines led by `;;' and a tab character, like this:
  775.           ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
  776.           ;;      Dave Sill <de5@ornl.gov>
  777.           ;;      Dave Brennan <brennan@hal.com>
  778.           ;;      Eric Raymond <esr@snark.thyrsus.com>
  779. `Maintainer'
  780.      This line should contain a single name/address as in the Author
  781.      line, or an address only, or the string `FSF'.  If there is no
  782.      maintainer line, the person(s) in the Author field are presumed to
  783.      be the maintainers.  The example above is mildly bogus because the
  784.      maintainer line is redundant.
  785.      The idea behind the `Author' and `Maintainer' lines is to make
  786.      possible a Lisp function to "send mail to the maintainer" without
  787.      having to mine the name out by hand.
  788.      Be sure to surround the network address with `<...>' if you
  789.      include the person's full name as well as the network address.
  790. `Created'
  791.      This optional line gives the original creation date of the file.
  792.      For historical interest only.
  793. `Version'
  794.      If you wish to record version numbers for the individual Lisp
  795.      program, put them in this line.
  796. `Adapted-By'
  797.      In this header line, place the name of the person who adapted the
  798.      library for installation (to make it fit the style conventions, for
  799.      example).
  800. `Keywords'
  801.      This line lists keywords for the `finder-by-keyword' help command.
  802.      This field is important; it's how people will find your package
  803.      when they're looking for things by topic area.  To separate the
  804.      keywords, you can use spaces, commas, or both.
  805.    Just about every Lisp library ought to have the `Author' and
  806. `Keywords' header comment lines.  Use the others if they are
  807. appropriate.  You can also put in header lines with other header
  808. names--they have no standard meanings, so they can't do any harm.
  809.    We use additional stylized comments to subdivide the contents of the
  810. library file.  Here is a table of them:
  811. `;;; Commentary:'
  812.      This begins introductory comments that explain how the library
  813.      works.  It should come right after the copying permissions.
  814. `;;; Change log:'
  815.      This begins change log information stored in the library file (if
  816.      you store the change history there).  For most of the Lisp files
  817.      distributed with Emacs, the change history is kept in the file
  818.      `ChangeLog' and not in the source file at all; these files do not
  819.      have a `;;; Change log:' line.
  820. `;;; Code:'
  821.      This begins the actual code of the program.
  822. `;;; FILENAME ends here'
  823.      This is the "footer line"; it appears at the very end of the file.
  824.      Its purpose is to enable people to detect truncated versions of
  825.      the file from the lack of a footer line.
  826. File: elisp,  Node: GNU Emacs Internals,  Next: Standard Errors,  Prev: Tips,  Up: Top
  827. GNU Emacs Internals
  828. *******************
  829.    This chapter describes how the runnable Emacs executable is dumped
  830. with the preloaded Lisp libraries in it, how storage is allocated, and
  831. some internal aspects of GNU Emacs that may be of interest to C
  832. programmers.
  833. * Menu:
  834. * Building Emacs::      How to preload Lisp libraries into Emacs.
  835. * Pure Storage::        A kludge to make preloaded Lisp functions sharable.
  836. * Garbage Collection::  Reclaiming space for Lisp objects no longer used.
  837. * Writing Emacs Primitives::   Writing C code for Emacs.
  838. * Object Internals::    Data formats of buffers, windows, processes.
  839.